package com.rykj.qxj.rest;

import com.github.pagehelper.PageInfo;
import com.rykj.qxj.server.services.ISystemLogService;
import com.rykj.qxj.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Log4j
@RestController
@RequestMapping("/v1/systemLog")
@Api(tags="系统日志")
public class SystemLogController {
	@Autowired
	private ISystemLogService systemLogService;
	
	@GetMapping("/list")
    @ApiOperation(value="系统日志分页列表",notes ="系统日志分页列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页数",required = true,paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "显示行数",required = true,paramType = "query"),
            @ApiImplicitParam(name = "userName", value = "用户名称",paramType = "query"),
            @ApiImplicitParam(name = "ip", value = "用户ip",paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间",paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间",paramType = "query")
    })
    public Result selectSystemLogBySearchParams(@RequestParam(value = "pageNum") Integer pageNum,
                                   @RequestParam(value = "pageSize") Integer pageSize,
                                   @RequestParam(value = "userName",required = false) String userName,
                                   @RequestParam(value="ip",required=false)String ip,
								  @RequestParam(value = "startTime",required = false) String startTime,
								  @RequestParam(value="endTime",required=false)String endTime){
        try{
		PageInfo page = systemLogService.selectSystemLogBySearchParams(pageNum, pageSize, userName,ip,startTime,endTime);
            return new Result(page);
        }catch (Exception e){
            log.error("查询失败", e);
            return new Result(false, "查询失败");
        }
        
    }

}
